//var ipp = require('ipp');
let Base64 = require('js-base64').Base64;

import { E_SYSTEM_AUTH_MODE, E_PASTE_TYPE, SeparatorCfg, BarCodeCfg, QCCfg, E_SET_MODE, E_FERRULE_MODE, ElementCfg, E_DOC_TYPE, E_DISPLAY_MODE, E_DOCS_ORGANIZE_MODE, E_PAGES_LAYOUT_MODE, E_VIEW_MODE, E_FORMULA_STYLE, E_LAYOUT_VERTICAL_ALIGN, E_BARCODE_TYPE, E_CHECK_FIGURE_STYLE, E_DOC_FORMAT, E_ALIGN_HORIZONTAL_MODE, E_IDENTITY_OBJECT_TYPE, SearchReplaceCfg, AttachCfg, E_LIST_MODEL, E_TIME_TYPE, E_IMAGE_TYPE } from '@/../public/js/ThinkEditor.Defined';

import { GetRandStr, ShowSaveFileDialog, PopFileSelector } from '@/../public/js/ThinkEditor.Utils';
import { ThinkEditor } from '@/../public/js/ThinkEditor';

export class ThinkEditorDemo {
  constructor(thinkEditor) {
    this.thinkEditor = thinkEditor;
  }
  bind(thinkEditor) {
    this.thinkEditor = thinkEditor;
  }
  // 全屏事件
  TTTT() {
    this.thinkEditor.SetViewMode(E_VIEW_MODE.Edit);
    this.thinkEditor.SetElementContent('sign', '');
    this.thinkEditor.SetViewMode(E_VIEW_MODE.Browse);
    var xml_str = this.thinkEditor.GetDoc(E_DOC_FORMAT.XML, E_DOC_TYPE.Entity);
    console.log(xml_str);
  }

  /*
     SetWaterMarkConfig
     SetUserDefinedMenu
    SetFontType
    SetFontSize
UnionTest
UnionTimeTest
SetElementContent
SetParagraphContent
Run
Quit
InsertSeparator
DeleteElement,
DisplayFontSetWindow,
DisplayParagraphSetWindow,
禁用右键菜单
SetDocConfig_禁止正文编辑
InsertPageNum
GetDoc
PrintDoc
SetElementSelectDateTime
SetElementSource
InputData
ToPlainTextByEscape
testDump
ReleaseEditor
CloseAllDoc
CloseDoc
     */
  async Test1() {
    var testCode = 'UnionTest';
    var json_cfg = {};
    switch (testCode) {
      case 'ReleaseEditor': {
        this.thinkEditor.UnInit();
        break;
      }
      case 'testDump': {
        this.thinkEditor.SetEditorConfig({ testDump: 1 });
        break;
      }

      case 'ToPlainTextByEscape': {
        var str1 = '(快&检) <1"0.00 mg/L11111&2\'222<222<23>3333>33"33>3\'';
        //'(快&amp;检) &lt;1&quot;0.00 mg/L11111&amp;2&apos;222&lt;222&lt;23&gt;3333&gt;33&quot;33&gt;3&apos;'
        var plainText1 = this.thinkEditor.ToPlainTextByEscape(str1);
        plainText1 += '<LF/>';

        var str2 = '(放入元素中&) <1"0.00 mg/L有特殊字符<23>3333>33"33>3\'';
        var plainText2 = this.thinkEditor.ToPlainTextByEscape(str2);
        plainText2 = '<Element>' + plainText2 + '</Element>';
        //'<Fragment>(快&amp;检) &lt;1&quot;0.00 mg/L11111&amp;2&apos;222&lt;222&lt;23&gt;3333&gt;33&quot;33&gt;3&apos;</Fragment>'
        var fragmentStr = '<Fragment>' + plainText1 + plainText2 + '</Fragment>';

        this.thinkEditor.InputData(fragmentStr);
        break;
      }
      case 'ToPlainTextByCDATA': {
        var str = '(快&检) <1"0.00 mg/L111<![CDATA[11&2\'222<222<23>33]]>33>33"33>3\'';
        //`<![CDATA[(快&检) <1"0.00 mg/L11111&2'222<222<23>3333>33"33>3']]>`
        var plainText = this.thinkEditor.ToPlainTextByCDATA(str);
        //`<Fragment><![CDATA[(快&检) <1"0.00 mg/L11111&2'222<222<23>3333>33"33>3']]></Fragment>`
        var fragmentStr = '<Fragment>' + plainText + '</Fragment>';

        this.thinkEditor.InputData(fragmentStr);
        break;
      }
      case 'SetElementSource': {
        var ele_cfg = new ElementCfg();
        ele_cfg.dynamic_load_ = true;
        this.thinkEditor.SetElementSource('DFE02698-0904-464D-8ED0-E66E67BFC9FB', '', '', ele_cfg);
        break;
      }
      case 'SetElementSelectDateTime':
        {
          this.thinkEditor.SetElementSelectDateTime('', 4);
        }
        break;
      case '':
        {
          console.log('--------PrintDoc-----------');

          this.thinkEditor.PrintDoc({
            sharpness: 2.0,
            rotate: 0,
            mode: 0,
            pagesRange: '',
            view: {
              mode: E_VIEW_MODE.Print,
              hideElementHint: true
            }
          });
        }
        break;
      case 'GetDoc_JsonXmlTest':
        {
          var docXml = this.thinkEditor.GetDoc(E_DOC_FORMAT.XML, E_DOC_TYPE.Entity);
          console.log(docXml);
          var docJson = JSON.parse(docXml);
          console.log(docJson.xml);
          var docStr = Base64.decode(docJson.xml);
          console.log(docStr);
        }
        break;
      case 'InsertPageNum':
        {
          this.thinkEditor.InsertPageNum({ scope: E_PAGE_NUM_SCOPE.WholeDocnment, style: E_PAGE_NUM_STYLE.OrderListModel_0, format: E_PAGE_NUM_FORMAT.PageOrderPagesCountFormat });
        }
        break;
      case 'SetDocConfig_禁止正文编辑':
        {
          json_cfg.dynamicLocked = true;
          this.thinkEditor.SetDocConfig('', json_cfg);
        }
        break;
      case '禁用右键菜单':
        {
          json_cfg.clipBoardMenuDisplayMode = 0;
          json_cfg.attributeMenuDisplayMode = 1;
          json_cfg.operationMenuDisplayMode = 0;
          this.thinkEditor.SetEditorConfig(json_cfg);
        }
        break;
      case 'DisplayFontSetWindow':
        {
          this.thinkEditor.DisplayFontSetWindow(E_DISPLAY_MODE.Show);
        }
        break;
      case 'DisplayParagraphSetWindow':
        {
          this.thinkEditor.DisplayParagraphSetWindow(E_DISPLAY_MODE.Show);
        }
        break;
      case 'DeleteElement':
        {
          this.thinkEditor.DeleteElement('');
        }
        break;
      case 'InsertSeparator':
        {
          this.thinkEditor.InsertSeparator('', 0, 0.2, {
            lineHight: 0.04
          });
        }
        break;
      case 'SetParagraphContent':
        {
          this.thinkEditor.SetParagraphContent('主诉', '无UI模式');
        }
        break;
      case 'SetElementContent':
        {
          this.thinkEditor.SetElementContent('简要诊断', '无UI模式');
        }
        break;
      case 'Copy':
        {
          this.thinkEditor.Copy();
        }
        break;
      case 'loseContext':
        {
          //模拟丢失
          this.thinkEditor.gl.getExtension('WEBGL_lose_context').loseContext();
        }
        break;
      case 'SetViewMode_fontColor':
        {
          json_cfg.fontColor = 'ff0000ff';
          this.thinkEditor.SetViewMode(E_VIEW_MODE.Edit, json_cfg);
        }
        break;
      case 'UnionTest':
        {
          //this.thinkEditor.CloseAllDoc();
          //新建文档编辑器
          var docName = '合并';
          var thinkEditor = new ThinkEditor({
            lib: '/js/', //库文件在服务器上路径
            fontPath: '/system/user_font/', //字体文件在服务器上路径
            editorId: docName + '_' + GetRandStr(), //文档编辑器Id，用于区分不同的文档编辑器
            auth: { mode: E_SYSTEM_AUTH_MODE.Demonstration, sourceId: '江东第一人民医院' }
          });

          await thinkEditor.Init();
          //tesw thinkEditor.SetEditorConfig({ auth: { mode: E_SYSTEM_AUTH_MODE.WatermarkAuth, sourceId: '江东第一人民医院' } });

          //test thinkEditor.SetEditorConfig({ auth: undefined });

          var url = '/system/emr/1.xml'; //"/system/test/pacsdemo.jpg";
          let response = await fetch(url, {
            credentials: 'same-origin'
          });
          let xml1 = await response.arrayBuffer();

          json_cfg.organizeMode = E_DOCS_ORGANIZE_MODE.UnionSection;
          json_cfg.recoverSelection = 2;
          json_cfg.setUnionSelection = 0;
          thinkEditor.CreateDoc('病程记录'); //@20220722 必需，才能设置编辑者信息
          thinkEditor.SelectDoc('病程记录');
          thinkEditor.SetEditorInfo('pc', 'zltest', 'zl', 1, '');
          thinkEditor.ParseDocs('病程记录', '首次病程记录-1-13333', xml1, json_cfg);

          url = '/system/emr/2.xml'; //"/system/test/pacsdemo.jpg";
          response = await fetch(url, {
            credentials: 'same-origin'
          });
          let xml2 = await response.arrayBuffer();
          json_cfg.organizeMode = E_DOCS_ORGANIZE_MODE.UnionSection;
          json_cfg.recoverSelection = 2;
          json_cfg.setUnionSelection = 1;
          thinkEditor.ParseDocs('病程记录', '首次病程记录-1-147449', xml2, json_cfg);

          url = '/system/emr/3.xml'; //"/system/test/pacsdemo.jpg";
          response = await fetch(url, {
            credentials: 'same-origin'
          });
          let xml3 = await response.arrayBuffer();
          json_cfg.organizeMode = E_DOCS_ORGANIZE_MODE.UnionSection;
          json_cfg.recoverSelection = 2;
          json_cfg.setUnionSelection = 0;
          thinkEditor.ParseDocs('病程记录', '首次病程记录-1-3', xml3, json_cfg);

          url = '/system/emr/4.xml'; //"/system/test/pacsdemo.jpg";
          response = await fetch(url, {
            credentials: 'same-origin'
          });
          let xml4 = await response.arrayBuffer();
          json_cfg.organizeMode = E_DOCS_ORGANIZE_MODE.UnionSection;
          json_cfg.recoverSelection = 2;
          json_cfg.setUnionSelection = 0;
          thinkEditor.ParseDocs('病程记录', '首次病程记录-1-4', xml4, json_cfg);

          //thinkEditor.SetViewMode(E_VIEW_MODE.Edit, {});

          let printCfg = {};
          printCfg.printMode = 1; // 0：视图打印 1：矢量打印
          printCfg.view = {
            mode: E_VIEW_MODE.Print,
            hideElementHint: true
          };

          //[0] 注意await,后续可能关闭文档或编辑器
          await thinkEditor.PrintDoc(printCfg);


          var docXml = thinkEditor.GetDoc(E_DOC_FORMAT.XML, E_DOC_TYPE.Entity, { multipleDocs: true });
          console.log(docXml);
          var docJson = JSON.parse(docXml);
          console.log('docJson', docJson);
          var docStr = Base64.decode(docJson[0].xml);
          console.log('文档1的xmlStr:', docStr);
          //[1]如果ThinkEditor还需使用，当前文档不需使用了，则关闭文档
          //thinkEditor.CloseDoc(docName);
          //或;
          //thinkEditor.CloseAllDoc();

          //[2]如果ThinkEditor不再使用了，则释放编辑器及内存
          console.warn('thinkEditor.UnInit()'); //必要，释放内存
          thinkEditor.UnInit();
        }
        break;
      case 'UnionTimeTest':
        {
          var url = '/system/emr/AdmissionRecord.xml'; //"/system/test/pacsdemo.jpg";
          let response = await fetch(url, {
            credentials: 'same-origin'
          });
          let xml1 = await response.arrayBuffer();

          json_cfg.organizeMode = 2;
          json_cfg.recoverSelection = 2;
          json_cfg.setUnionSelection = 0;

          console.time('UnionTimeTest1');
          for (var i = 0; i < 100; i++) {
            this.thinkEditor.ParseDocs('0', i + '', xml1, json_cfg);
          }
          console.timeEnd('UnionTimeTest1');

          console.time('UnionTimeTest2');
          this.thinkEditor.SetViewMode(E_VIEW_MODE.Edit, {});
          console.timeEnd('UnionTimeTest2');
        }
        break;
      case 'SetFontType':
        this.thinkEditor.SetFontType('黑体');
        break;
      case 'SetWaterMarkConfig':
        var attach_id = 'waterMarkTest';
        json_cfg.fontName = '宋体';
        json_cfg.size = 1.0;
        json_cfg.Fragment = '文字水印测试';

        json_cfg.angle = 315;

        json_cfg.forbidPrint = 0;
        json_cfg.repeat = 1;
        json_cfg.fillMode = 0;

        json_cfg.topPadding = 2.8;
        json_cfg.bottomPadding = 2.8;
        json_cfg.leftPadding = 2.8;
        json_cfg.right_Padding = 2.8;

        //json_cfg.top_padding = 1.8;
        //json_cfg.bottom_padding = 1.8;
        //json_cfg.left_padding = 1.8;
        //json_cfg.right_padding = 1.8;

        this.thinkEditor.SetWaterMarkConfig(attach_id, json_cfg);
        break;
      case 'SetUserDefinedMenu':
        //var json_str = `[{"type":"user_defined1","text":"自定义菜单1","code":0},{"type":"user_defined2","text":"自定义菜单2","code":2}]`;
        var json_str = `[]`;
        var json_obj = JSON.parse(json_str);
        this.thinkEditor.SetUserDefinedMenu(json_obj);
        break;
      default:
        break;
    }

    return;
    /*
        this.thinkEditor.SetElementSelectDateTime("name", E_TIME_TYPE.DateTime);
        */
    /*
        const json = {};
        json.srcDocName = "Compare1";
        json.destDocName = "Compare2";

        var url = "/system/emr/Compare1.xml";//"/system/test/pacsdemo.jpg";
        let response = await fetch(url,  {credentials:'same-origin'});
        let src_data = await response.arrayBuffer();
        url = "/system/emr/Compare2.xml";//"/system/test/pacsdemo.jpg";
        response = await fetch(url,  {credentials:'same-origin'});
        let dest_data = await response.arrayBuffer();
        this.thinkEditor.SetCompareDocs(json,src_data,dest_data);
        return;
*/
    /*
        const json1 = {};
        json1.ids = [];
        json1.ids[0] = "asdf";
        json1.ids[1] = "test";
        this.thinkEditor.SelectAnnotates(json1);
        return;
*/
    /*
        var json_obj={};
        json_obj.locked = 1;
        //json_obj["top-border-style"] = 0;
        this.thinkEditor.SetHeaderConfig(json_obj);
        return;*/
    /*
        var json = {};
        json.hide = true;
        //json.display_revise_del = false;
        //json.display_qualitycontrol_infobox
        await this.thinkEditor.SetParagraphConfig("主诉", json);
        return;    */
    /*
       this.thinkEditor.SetElementContent("6CAEC966-0CC7-4C7D-ACFC-8436704A4708", "5689");
       this.thinkEditor.GetDoc(E_DOC_FORMAT.XML,E_DOC_TYPE.Entity);
       return;    */
    /*var json_cfg ={};
        json_cfg.check_figure_style =0;
        json_cfg.multiple_choice =1;
        this.thinkEditor.InsertCheckBoxGroup("1234", "病史", "吸烟史", json_cfg);
*/
    /*
    var json_cfg ={};
    //json_cfg.organizeMode = E_DOCS_ORGANIZE_MODE.MergeContent;
    json_cfg.organizeMode = E_DOCS_ORGANIZE_MODE.UnionContent;
    //json_cfg.organizeMode = E_DOCS_ORGANIZE_MODE.UnionSection

    this.thinkEditor.CreateDoc("frist");

    this.thinkEditor.SetEditorInfo("pc", "zltest","zl",1,"");

    var url = "/system/test/merge_test/JumpDemo.xml";//"/system/test/pacsdemo.jpg";
    let emr_response = await fetch(url,  {credentials:'same-origin'});
    let data = await emr_response.arrayBuffer();
    this.thinkEditor.ParseDocs("frist", "", data, json_cfg);

    var url = "/system/test/merge_test/wg20220211.xml";//"/system/test/pacsdemo.jpg";
    emr_response = await fetch(url,  {credentials:'same-origin'});
    data = await emr_response.arrayBuffer();
    this.thinkEditor.ParseDocs("frist", "1", data, json_cfg);

    var url = "/system/test/merge_test/wg20220208.xml";//"/system/test/pacsdemo.jpg";
    emr_response = await fetch(url,  {credentials:'same-origin'});
    data = await emr_response.arrayBuffer();
    this.thinkEditor.ParseDocs("frist", "2", data, json_cfg);


    this.thinkEditor.SetViewMode(E_VIEW_MODE.Edit,{});

    return;*/
    /*
    this.thinkEditor.SetParagraphListMode(E_LIST_MODEL.OrderListModel_5);
    return;*/
    /*
        var url = "/system/test/668888.jpg";//"/system/test/pacsdemo.jpg";
        //var thinkEditorDemo = this;
        let response = await fetch(url,  {credentials:'same-origin'});
        let img_data = await response.arrayBuffer();
        var img_name = "668888.jpg";
        var img_md5 = this.thinkEditor.SetImageResource(img_name, img_data, img_data.length);
        console.log(img_md5);


        var attach_id = "waterMarkImg";

        let json_cfg={};
        json_cfg.image_name = img_name;
        json_cfg.md5 = img_md5;
        json_cfg.alpha = 0xff;
        json_cfg.forbid_print = 1;
        json_cfg.repeat = 0;
        json_cfg.fill_mode = 1;

        json_cfg.top_padding = 0;
        json_cfg.bottom_padding = 0;
        json_cfg.left_padding = 0;
        json_cfg.right_padding = 0;

        //json_cfg.top_padding = 1.8;
        //json_cfg.bottom_padding = 1.8;
        //json_cfg.left_padding = 1.8;
        //json_cfg.right_padding = 1.8;

        this.thinkEditor.SetWaterMarkConfig(attach_id, json_cfg);
*/
    /*
    let attach_cfg = new AttachCfg();
    attach_cfg.layer_ = 0;
    attach_cfg.type_ = 1;
    attach_cfg.source_ = 0;
    attach_cfg.forbid_print_ = 1;
    attach_cfg.texture_type_ = 0;
    attach_cfg.repeat_ = 1;
    let ret1 = this.thinkEditor.SetWaterMarkImage(attach_id,0xff, 0, 0,attach_cfg,img_name, img_md5);
    console.log(ret1);
    */
    //let ret2 = this.thinkEditor.SetWaterMarkPadding(attach_id,1.8, 1.8,1.8, 1.8);
    // console.log(ret2);

    /*
        var editor_config={};
        //editor_config.debug_flush = true;
        editor_config.disable_edit_limit = true;
        this.thinkEditor.SetEditorConfig(editor_config);
*/
    /*
         var json = {};
         var commnet_id = this.thinkEditor.InsertComment("","", json);
         var tt = commnet_id;
         */
    /*
        var json = {};
        json.trigger_type = 0;
        json.execute_mode = 0;
        json.action = `this.element.value=='吸烟' ? smoke.element.visible=true:smoke.element.visible=false`;

        await this.thinkEditor.SetElementConfig("", json);
*/
    /*
var json = {};
json.forbid_series_split = true;
json.split_paragrah_mode = 2;
//json.display_revise_del = false;
//json.display_qualitycontrol_infobox
await this.thinkEditor.SetParagraphConfig("123", json);

*/
    /*
            var editor_config={};
    //editor_config.debug_flush = true;
    editor_config.debug_event = true;
    editor_config.log_level = 10;
    this.thinkEditor.SetEditorConfig(editor_config);
*/

    /*
var json = {};
json.delete_mode = true;
json.split_paragrah_mode = 1;
//json.display_revise_del = false;
//json.display_qualitycontrol_infobox
this.thinkEditor.SetElementConfig("", json);
        //this.thinkEditor.SetElementBase("", "设置-测试", "", "{", "}", "", "");
        //const cfg = new SearchReplaceCfg();
//const aa = this.thinkEditor.GetObjectFragment(E_IDENTITY_OBJECT_TYPE.Paragraph, "103",E_DOC_FORMAT.XML, cfg);
*/
    /*
thinkEditor.DisplayImageSetWindow(1);
//return;*/
    //this.thinkEditor.DisplayElementSetWindow(1);
    /*
    this.thinkEditor.DisplaySearchReplaceWindow(1);
           return;  */

    /*
//var json = {};
//json.display_revise_auxiliary = true;
//json.display_revise_del = false;
//json.display_qualitycontrol_infobox = false;
//json.display_comment_infobox = false;
json.display_carriage_return = false;
json.display_trim_marks = true;
this.thinkEditor.SetViewMode(E_VIEW_MODE.Edit, json);
        //this.thinkEditor.CloseAllDoc();
        //this.thinkEditor.DisplayEditToolBar(E_DISPLAY_MODE.Hide);
        return;
        var init_config={
        doc_rename: "new1111", // #2e83f8

        };
      this.thinkEditor.SetDocConfig("", init_config);
*/

    /*
  //var signImage = "R0lGODdhwgEsAcYAAP//////ABkAAP//3///X///n///H///v///f///P///w///b///J+Lf329fX6ifnzUfE8W/v4x/fzUfG4x/X8W/p29fL6ifd1I/F8W/dzUfH1I/D6ifTzUfAOLfp29fF4x/T1I/B29fI1I/H6ifJ29fU4x/LzUfB8W/X4x/D4x/b+LfbzUfD29fO8W/AG9fC1I/AKifO+LfADUfA+LfG+Lfw+LfizUfC29fR1I/P6ifAFI/J29fAIx/AIx/P8W/F+LfU8W/RzUfGMW/L+LfN1I/LzUfF1I/N8W/j6ifY6ifi6ifE8jDw31vb4x/H31vADwnJwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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Ow==";
  var md5 = this.thinkEditor.SetImageResourceBase64("sign.bmp", signImage, signImage.length, "");// (E_VIEW_MODE::Edit);
  var signFragment = "<Fragment><Image width='2' height='0.8' file='当前医师电子签名.jpg' md5='" + md5 + "'/></Fragment>";

  this.thinkEditor.SetElementContent("sign", signFragment);
*/
    //this.handleFullScreen();
    //var doc_name = this.thinkEditor.GetVisibleDocName();
    //this.thinkEditor.CloseDoc(doc_name);

    /*
       //---------------
        var init_config={
        tab_color: "FF2E83F9", // #2e83f8
       //tab_hovered_color: "FF83BDFF", // #82beff
       //tab_active_color: "FF0076FF", //
        };
        //init_config.tab_color = "ffff0000";//0xffff0000;
      this.thinkEditor.SetEditorConfig(init_config);
*/

    //this.thinkEditor.ResizeViewPanel(1000,1000);
    //---------------
    //this.thinkEditor.CloseAllDoc();

    //---------------
    //var ret =  this.thinkEditor.SetSelectContentLock(true);
    //var ret =  this.thinkEditor.InsertElement("test", "请输入", "", "[", "]", "", "");
    //var test = this.thinkEditor.GetSelectRangeContent(E_DOC_FORMAT.TEXT);
    //---------------
    /*
    var json_obj={};
    json_obj.display = 0;
    //json_obj["top-border-style"] = 0;
    this.thinkEditor.SetHeaderConfig(json_obj);
    this.thinkEditor.SetFooterConfig(json_obj);
    */
    //-------------------
    //this.thinkEditor.GetSelectDocName();
    //var editorContainer = this.$refs.editorContainer;
    //editorContainer.width = 1000;
    //editorContainer.height = 1000;
    // this.thinkEditor.ResizeViewPanel(1000,1000);
    //var ret = this.thinkEditor.SetElementContent("简要诊断", '<Fragment><Format size=\"0.776\" />XXX人民医院</Fragment>');
    //---------------
    //var cfg = new SeparatorCfg();
    //cfg.all = 0;
    //cfg.independent_line_ = true;
    //this.thinkEditor.InsertSeparator("", 0, 0.04,0xFF000000, cfg);
    //---------------
    // this.thinkEditor.DisplayBarCodeSetWindow(E_DISPLAY_MODE.Show,E_SET_MODE.InsertSpecial);
    //this.thinkEditor.DisplayImageSetWindow(E_DISPLAY_MODE.Show,E_SET_MODE.SM_INSERT_COMMON);

    //---------------
    //var docname = this.thinkEditor.GetSelectDocName();
    //console.log(docname);
    //docname = this.thinkEditor.GetVisibleDocName();
    //console.log(docname);
    //---------------
    //      this.thinkEditor.SetParagraphAlignContent(E_ALIGN_HORIZONTAL_MODE.Center);
    //---------------
    // var outline = this.thinkEditor.GetOutline();
    // var gotoOutline =`{\"type\":\"Section\",\"index\":0,\"content\":{\"type\":\"Main\",\"Paragraph\":{\"type\":\"Paragraph\",\"id\":\"主诉\",\"name\":\"\",\"level\":0,\"index\":3,\"member\":{\"type\":\"Element\",\"id\":\"简要诊断\",\"name\":\"\"}}}}`;
    //var ret = this.thinkEditor.GotoOutline(gotoOutline);

    //---------------
    //this.thinkEditor.DisplayElementSetWindow(E_DISPLAY_MODE.Show,E_SET_MODE.SM_INSERT_COMMON);
    //---------------
    //this.thinkEditor.SetParagraphSpaceBefore(1);
    //---------------
    //this.thinkEditor.SetFontFerrule(E_FERRULE_MODE.Circle);
    //---------------
    //this.thinkEditor.SetBackgroundColor(this.$BuildTEColorByStr("rgb(66, 133, 244)"));
  }

  /*
     SetViewMode
CancelCompareDocs
Paste
Exit
     */

  Test2() {
    var testCode = 'Paste';
    switch (testCode) {
      case 'testDump1':
        this.thinkEditor.SetEditorConfig({ testDump1: 1 });
        break;
      case 'Exit':
        this.thinkEditor.Exit();
        break;
      case 'Paste':
        this.thinkEditor.Paste(E_PASTE_TYPE.Normal);
        break;
      case 'SetViewMode':
        this.thinkEditor.SetViewMode(E_VIEW_MODE.Print, {});
        break;
      case 'CancelCompareDocs':
        var json_cfg = {};
        json_cfg.retainDocs = true;
        this.thinkEditor.CancelCompareDocs(json_cfg);
        break;
      default:
        break;
    }

    return;
    /*
            this.thinkEditor.SetElementContent("6CAEC966-0CC7-4C7D-ACFC-8436704A4708", "5689");
            this.thinkEditor.GetDoc(1,0);
            return;
            */
    /*
this.thinkEditor.DisplayImageEdit(1);
return;*/

    var json = {};
    /*
 json.display_edit_auxiliary = true;//change
 json.display_selection_effect = true;
 json.display_revise_auxiliary = true;
 json.display_revise_del = true;
 json.display_qualitycontrol_infobox = false;
 json.display_comment_infobox = true;
*/
    json.displayCommentMode = 2;
    //json.display_trim_marks = false;
    this.thinkEditor.SetViewMode(E_VIEW_MODE.Edit, json);
    //this.thinkEditor.DisplayEditToolBar(E_DISPLAY_MODE.Hide);
    return;
    var json_obj = {};
    json_obj.display = 1;
    //json_obj["top-border-style"] = 0;
    this.thinkEditor.SetHeaderConfig(json_obj);
    this.thinkEditor.SetFooterConfig(json_obj);
  }
  SetUserDefinedMenuDemo() {
    var json_str = `[{"type":"user_defined1","text":"自定义菜单1","code":0},{"type":"user_defined2","text":"自定义菜单2","code":2}]`;
    var json_obj = JSON.parse(json_str);
    this.thinkEditor.SetUserDefinedMenu(json_obj);
  }
  SetViewModeShowReviseEdit(thinkEditor) {
    thinkEditor.SetEditorInfo('pc', '12666', 'admin', 1, { note: '上级医师审阅修改' });
    thinkEditor.SetEditMode(true, true, true, false, false);
    thinkEditor.SetViewMode(E_VIEW_MODE.Edit, { displayReviseAuxiliary: true, displayReviseDel: true });
  }
  SetViewModeHideReviseEdit(thinkEditor) {
    thinkEditor.SetEditorInfo('pc', '12666', 'admin', 1, { note: '上级医师审阅修改' });
    thinkEditor.SetEditMode(true, true, true, false, false);
    thinkEditor.SetViewMode(E_VIEW_MODE.Edit, { displayReviseAuxiliary: false, displayReviseDel: false });
  }
  SetViewModeNullReviseEdit(thinkEditor) {
    thinkEditor.SetEditorInfo('pc', '12666', 'admin', 1, { note: '上级医师审阅修改' });
    thinkEditor.SetEditMode(false, false, false, false, false);
    thinkEditor.SetViewMode(E_VIEW_MODE.Edit);
  }
  CancelSign() {
    this.thinkEditor.SetViewMode(E_VIEW_MODE.Edit);
    this.thinkEditor.SetElementContent('sign', '');
    this.thinkEditor.SetViewMode(E_VIEW_MODE.Browse);
  }

  async SelectImage() {
    var fileData = await PopFileSelector('.jpg,.svg,.bmp,.png,');
    var data = fileData.data;
    var imgName = fileData.fileName;
    this.thinkEditor.InsertImage('', 0, 0, imgName, data, data.byteLength, {});
  }
  RandomString(len) {
    len = len || 32;
    var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'; /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
    var maxPos = $chars.length;
    var pwd = '';
    for (var i = 0; i < len; i++) {
      pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
    }
    return pwd;
  }
  async OpenDoc() {
    var docData = await PopFileSelector('.xml,');
    var docName = docData.fileName; //this.RandomString(9);
    var data = docData.data;
    /************************
     * 方案一：简化示例 没有加载资源
     * *************************/
    //this.thinkEditor.CreateDoc(doc_name);
    //this.thinkEditor.ParseDoc(doc_name, data, E_DOCS_ORGANIZE_MODE.Single);
    //this.thinkEditor.SetDisplayScale(E_PAGES_LAYOUT_MODE.Ratio, 1.2);
    //this.thinkEditor.SetViewMode(E_VIEW_MODE.Edit);
    /************************
     * 方案二：通用演示
     * *************************/
    this.OpenEmrCommon(docName, data);
  }
  NewTemplateDoc() {
    var doc_name = this.RandomString(9);
    //需要把empty.xml换成empty.xml的 data数据
    this.OpenEmr(doc_name, E_DOC_TYPE.Template, 'empty.xml');
    this.PreLoadTemplateSource();
  }
  async NewEntityDoc() {
    //this.thinkEditor.CloseAllDoc();
    var doc_name = this.RandomString(9);
    await this.OpenEmr(doc_name, E_DOC_TYPE.Entity, 'empty.xml');
    /*
            const new_doc =`<Doc>
     <Sections>
      <Section>
       <Main>
        <Paragraph id="1212">
        段落内容
        </Paragraph>
       </Main>
      </Section>
     </Sections>
     <Resources />
    </Doc>`

    const json_cfg={};
    json_cfg.replace_main_content = true;
    this.thinkEditor.AppendFragment('',new_doc, json_cfg);

    const json_p_cfg={};
    json_p_cfg.forbid_series_split =true;
    json_p_cfg.split_paragrah_mode =2;
    this.thinkEditor.SetParagraphConfig("1212",json_p_cfg);
    */
  }
  async NewTimeAxis() {
    var url = '/system/emr/TemperatureTimeAxis.xml'; //"/system/test/pacsdemo.jpg";
    //var thinkEditorDemo = this;
    let response = await fetch(url, {
      credentials: 'same-origin'
    });
    let data = await response.arrayBuffer();
    //response.arrayBuffer().then(data =>  {
    var doc_name = '体温单' + ((Math.random() * 1000000) | 0);
    this.OpenEmrCommonHandle(doc_name, data);

    var d = new Date();
    var timeS = parseInt(d.getTime() / 1000);

    var json = {};
    json['id'] = '';
    json['startTime'] = timeS; //注意传float 编辑器json会读取不到数据，需使用parseInt
    json['endTime'] = timeS + 6 * 86400; //当前页面宽度 6天为一页
    this.thinkEditor.SetTimeGridConfig(json);
    this.thinkEditor.UpdateTimeAxis('');
    this.thinkEditor.SetViewMode(E_VIEW_MODE.Browse);
  }
  SaveToPdfView() {
    var dataBuffer = this.thinkEditor.GetPagesPDF(0, 10, 1.5, 0);
    ShowSaveFileDialog('thinkeditor.pdf', dataBuffer);
  }
  async SaveToPdf() {
    var dataBuffer = await this.thinkEditor.GetPDF({});
    ShowSaveFileDialog('thinkeditor.pdf', dataBuffer);
  }
  SaveToXml(docType = E_DOC_TYPE.Entity) {
    var dataBuffer = this.thinkEditor.GetDoc(E_DOC_FORMAT.XML, docType);
    ShowSaveFileDialog('thinkeditor.xml', dataBuffer);
  }
  SaveToXmlTemplate() {
    var dataBuffer = this.thinkEditor.GetDoc(E_DOC_FORMAT.XML, E_DOC_TYPE.Template);
    ShowSaveFileDialog('thinkeditorTemplate.xml', dataBuffer);
  }
  SaveToHtml() {
    var dataBuffer = this.thinkEditor.GetDoc(E_DOC_FORMAT.HTML, E_DOC_TYPE.Entity);
    ShowSaveFileDialog('thinkeditor.html', dataBuffer);
  }
  SaveToImg() {
    var dataBuffer = this.thinkEditor.GetPagesImage(E_IMAGE_TYPE.JPG, 0, 2, 1);
    ShowSaveFileDialog('thinkeditor.jpg', dataBuffer);
  }
  async InsertImage() {
    var url = '/system/test/sign.svg'; //"/system/test/pacsdemo.jpg";
    let response = await fetch(url, {
      credentials: 'same-origin'
    });
    let data = await response.arrayBuffer();
    await this.thinkEditor.InsertImage('', 0, 0, 'pacsdemo', data, data.byteLength, {});
  }
  async LoadSystemKnowledge() {
    var json_str = `[
	{
		"class": "系统123",
		"Options": [
			{
				"id": "属地567",
				"multiple_choice": false,
				"group_exclusion": true,
				"Items": [
					{
						"id": "本县区888",
						"group-id": "",
						"weight": 1.00,
						"content": "*fragment_base64*"
					},
					{
						"id": "本市其他县区",
						"group-id": "",
						"weight": 1.00
					},
					{
						"id": "本省其他地市",
						"group-id": "",
						"weight": 1.00
					},
					{
						"id": "外省",
						"group-id": "",
						"weight": 1.00
					},
					{
						"id": "港澳台",
						"group-id": "",
						"weight": 1.00
					},
					{
						"id": "外籍",
						"group-id": "",
						"weight": 1.00
					}
				]
			}
		]
	}
]`;
    let thinkEditor = this.thinkEditor;
    var json_obj = JSON.parse(json_str);
    thinkEditor.AddSystemKnowledge(json_obj);
    /************************************
     * 加载 系统知识库，比如姓别 省份
     * ***********************************/

    var url = '/system/knowledge/System/System.xml';
    let response_system = await fetch(url, {
      credentials: 'same-origin'
    }); //.then(function (response) {
    let data_system = await response_system.arrayBuffer();
    thinkEditor.AddSystemKnowledge(data_system);

    /************************************
     * 加载通用知识库
     * ***********************************/

    var url = '/system/knowledge/Common/CommonSymptoms.xml';
    let response_common = await fetch(url, {
      credentials: 'same-origin'
    }); //.then(function (response) {
    let data_common = await response_common.arrayBuffer();
    thinkEditor.AddSystemKnowledge(data_common);
  }
  async LoadDocKnowledge(doc_class) {
    /************************************
     * 加载科室知识库
     * ***********************************/
    let thinkEditor = this.thinkEditor;
    if (doc_class == '呼吸科') {
      var url = '/system/knowledge/Respiratory/Respiratory.xml';
      let response = await fetch(url, {
        credentials: 'same-origin'
      });
      let data = await response.arrayBuffer();
      thinkEditor.AddDocKnowledge(doc_class, data);
    } else if (doc_class == '感染科') {
      var url = '/system/knowledge/InfectiousDisease/InfectiousDiseaseCard.xml';
      let response = await ffetch(url, {
        credentials: 'same-origin'
      });
      let data = await response.arrayBuffer();
      thinkEditor.AddDocKnowledge(doc_class, data);
    }
  }
  InsertFormula() {
    this.thinkEditor.InsertFormula({ id: '', style: E_FORMULA_STYLE.MensesStyle_1, alignVerticalLayout: E_LAYOUT_VERTICAL_ALIGN.OtherMiddle });
  }
  InsertCheckBox() {
    this.thinkEditor.InsertCheckBox({ id: '', weight: 0, content: '选框示例', checkFigureStyle: E_CHECK_FIGURE_STYLE.STYLE_1 });
  }
  InsertQRCode() {
    this.thinkEditor.InsertBarCode({ id: '', width: 1.5, height: 1.5, data: Base64.encode('123456789'), type: E_BARCODE_TYPE.QRCODE });
  }
  InsertBarCode() {
    this.thinkEditor.InsertBarCode({ id: '', width: 3, height: 1.5, data: Base64.encode('123456789'), type: E_BARCODE_TYPE.CODE128 });
  }
  InsertElement() {
    //this.thinkEditor.InsertElement("test", "请输入", "", "[", "]", "体温", "C");
    //"test", "请输入", "", "[", "]", "", ""
    let jsonCfg = {
      id: 'test',
      hint: '请输入',
      tip: '',
      startborder: '[',
      endBorder: ']',
      beforeTag: '',
      afterTag: ''
    };
    this.thinkEditor.InsertElement(jsonCfg);

    var ele_cfg = new ElementCfg();
    ele_cfg.dynamic_load_ = false;
    //示例：设置引用源
    this.thinkEditor.SetElementSource('test', '基本资料', '医保号', ele_cfg);

    //示例：设置选项输入
    ele_cfg.multiple_choice_ = false;
    //this.thinkEditor.SetElementSelectOption("", "系统", "良好程度", "",ele_cfg);
    //this.thinkEditor.SetElementSelectOption("", "系统123", "属地567", "",ele_cfg);
    //this.thinkEditor._SetEditorCanvasFoucs(true);
    //this.Module.canvas = canvasObj;
  }

  async InsertFragment(fragment_file) {
    var url = '/system/fragment/' + fragment_file;
    let response = await fetch(url, {
      credentials: 'same-origin'
    });
    let data = await response.arrayBuffer();
    this.thinkEditor.InputFragment(data);
  }
  async AppendFragment(fragment_file) {
    var url = '/system/fragment/' + fragment_file;
    let response = await fetch(url, {
      credentials: 'same-origin'
    });
    let data = await response.arrayBuffer();
    //this.thinkEditor.ParseDoc("",data, E_DOCS_ORGANIZE_MODE.UnionContent);
    var json_cfg = {};
    //json_cfg.replace_main_content = true;
    this.thinkEditor.AppendFragment('', data, json_cfg);
  }
  async AppendFragment1() {
    //this.thinkEditor.ParseDoc("",data, E_DOCS_ORGANIZE_MODE.UnionContent);
    var json_cfg = {};
    //json_cfg.replace_main_content = true;
    this.thinkEditor.AppendFragment('', this.$emr, json_cfg);
  }
  PreLoadEntitySourceData() {
    console.log('PreLoadEntitySourceData');
    let thinkEditor = this.thinkEditor;
    thinkEditor.SetSource('认证', '机构名', "<Fragment><Format size='0.776' />江东第一人民医院</Fragment>");

    /********************病人基础资料*************************/
    thinkEditor.SetSource('基本资料', '姓名', '张小北');
    thinkEditor.SetSource('基本资料', '性别', '男');
    thinkEditor.SetSource('基本资料', '身份证', '5131246845698xxxxx');
    thinkEditor.SetSource('基本资料', '年龄', '23');
    thinkEditor.SetSource('基本资料', '民族', '汉');
    thinkEditor.SetSource('基本资料', '医保号', '1982309');

    //--------
    //this.thinkEditor.SetSource("门诊资料", "门诊号", "237899");
    thinkEditor.SetSource('门诊资料', '门诊号', "<Fragment><BarCode width='1.50' height='1.50' cfg='13a'>MTIzNDU2Nzg5</BarCode></Fragment>"); // "237899");

    thinkEditor.SetSource('住院资料', '住院号', 'new163679'); //163679
    thinkEditor.SetSource('住院资料', '科室', '骨科');
    thinkEditor.SetSource('住院资料', '病房', '6');
    thinkEditor.SetSource('住院资料', '床号', '16');
    thinkEditor.SetSource('住院资料', '入院时间', '2019-09-09 09:16:23');

    /***********************************
     * 设置图片源-此处用作签名
     * md5为图片二进制数据对应的md5码
     * 注意：图片数据在"imageResource.request"事件中调用SetImageResource/SetImageResourceBase64设置
     * 详见《设计手册-图像》
     * ************************************/
    var md5 = 'a04cfa91f403f799ce07252e85bda12b'; //md5必需为图片真实md5值
    var signSource = "<Fragment><Image width='2' height='0.8' file='当前医师电子签名.jpg' md5='" + md5 + "'/></Fragment>";
    thinkEditor.SetSource('医师资料', '电子签名', signSource);
    /*******************上级医师********************/
    md5 = 'b3aa75a6c69fb17ec3cc4290bbea8a57'; //md5必需为图片真实md5值
    signSource = "<Fragment><Image width='2' height='0.8' file='审核医师电子签名.jpg' md5='" + md5 + "'/><Format color='c93756' size='0.6'/>/</Fragment>";
    thinkEditor.SetSource('医师资料', '审核医师签名', signSource);
  }
  /**
   * 预设空数据源，用于编辑模板时元素-源类型选框中有对应数据
   * SetSource的source-class、source-id参数都是由应用自行规划取名和分类的
   * @memberof ThinkEditorDemo
   */
  PreLoadTemplateSource() {
    console.log('PreLoadTemplateSource');
    var thinkEditor = this.thinkEditor;
    thinkEditor.SetSource('认证', '机构名', '');
    /********************病人基础资料*************************/
    thinkEditor.SetSource('基本资料', '姓名', '');
    thinkEditor.SetSource('基本资料', '性别', '');
    thinkEditor.SetSource('基本资料', '身份证', '');
    thinkEditor.SetSource('基本资料', '年龄', '');
    thinkEditor.SetSource('基本资料', '民族', '');
    thinkEditor.SetSource('基本资料', '医保号', '');

    //--------
    thinkEditor.SetSource('门诊资料', '门诊号', '');

    thinkEditor.SetSource('住院资料', '住院号', '');
    thinkEditor.SetSource('住院资料', '科室', '');
    thinkEditor.SetSource('住院资料', '病房', '');
    thinkEditor.SetSource('住院资料', '床号', '');
    thinkEditor.SetSource('住院资料', '入院时间', '');
    /***********************************
     * 设置图片源-此处用作签名
     * md5为图片二进制数据对应的md5码
     * 注意：图片数据在"imageResource.request"事件中调用SetImageResource/SetImageResourceBase64设置
     * 详见《设计手册-图像》
     * ************************************/
    var md5 = 'a04cfa91f403f799ce07252e85bda12b'; //md5必需为图片真实md5值
    var signSource = "<Fragment><Image width='2' height='0.8' file='当前医师电子签名.jpg' md5='" + md5 + "'/></Fragment>";
    thinkEditor.SetSource('医师资料', '电子签名', signSource);
    /*******************上级医师********************/
    md5 = 'b3aa75a6c69fb17ec3cc4290bbea8a57'; //md5必需为图片真实md5值
    signSource = "<Fragment><Image width='2' height='0.8' file='审核医师电子签名.jpg' md5='" + md5 + "'/><Format color='c93756' size='0.6'/>/</Fragment>";
    thinkEditor.SetSource('医师资料', '审核医师签名', signSource);
  }

  /**
   * 供应用参考的封装打开文档的方法
   *
   * @param {string} doc_name
   * @param {string or ArrayBuffer} data
   * @param {E_DOC_TYPE} doc_type
   * @memberof ThinkEditorDemo
   */
  OpenEmrCommonHandle(doc_name, data, doc_type, enableRevise) {
    let cluster_name = doc_name;
    let thinkEditor = this.thinkEditor;

    thinkEditor.CreateDoc(cluster_name);
    thinkEditor.SelectDoc(cluster_name);
    //thinkEditor.VisibleDoc(cluster_name);
    /*V2版本 改为 CreateDocEditor后，加载对应源到DocEditorEntity
    if (doc_type == E_DOC_TYPE.Template) {
      //note:编辑模板前需预设空Source
      this.PreLoadTemplateSource();
    } else if (doc_type == E_DOC_TYPE.Entity) {
      //note:编辑文档实体时，无需预设Source, 而是动态获取，详见setElementContent.request事件处理
      this.PreLoadEntitySourceData(); //@20220610为演示方便，增加加载签名Source
    }

    */
    /*
        必需先解析ParseDoc文档中的编辑信息，再加载此次的编辑者信息
    */
    //thinkEditor.SetEditorInfo("pc", "12666", "admin", 0, {"note":"上级医师审阅修改"});//考虑到json_str xml_str存放可以扰乱xml问题attach_str=json_str
    /*
        SetEditorInfo的attrs_json参数和格式由用户自定义
    */
    var attrs_json = {};
    attrs_json.note = '上级医师审阅修改';
    thinkEditor.SetEditorInfo('pc', '12666', 'admin', 1, attrs_json); //考虑到json_str xml_str存放可以扰乱xml问题attach_str=json_str

    /*
    enable_permission:[是否可删除]启用文档内容安全和权限控制。默认为false文档内容可任意编辑。
    enable_revise:[是否逻辑删除 新增内容带痕]使能审阅模式。默认为false，正常编辑
    modify_same_level:能否修改或删除同授权等级的内容,默认为true
    force_modify: 高权限的是否可以修改低权限禁止删除、或禁止编辑的内容。 默认为false不可修改
    modify_owner_old_by_revise: 是否带痕修改自己曾经输入的内容，默认false,可直接删除自己写的旧内容
    */
    //thinkEditor.SetEditMode(true, true, false, false, false);

    //在加载文档之后，可修改

    thinkEditor.SetDocType(doc_type);

    thinkEditor.ParseDoc(cluster_name, data, E_DOCS_ORGANIZE_MODE.Single);

    if (enableRevise == 1) {
      thinkEditor.SetEditMode(true, true, true, false, false);
    } else {
      thinkEditor.SetEditMode(false, false, false, false, false);
    }

    thinkEditor.SetDocClass('呼吸科');
    thinkEditor.SetDisplayScale(E_PAGES_LAYOUT_MODE.Ratio, 1.0);

    //取得该文档需要的源信息
    //thinkEditor.SetViewMode(E_VIEW_MODE.Edit);
  }
  OpenEmrCommon(doc_name, data, doc_type, view_mode, enableRevise) {
    let thinkEditor = this.thinkEditor;

    /** [Error][CreateDoc 2620](0) 严重异常：！V2版本需控制一个thinkEditor只打开一个文档！A.打开新文档请重新new ThinkEditor 或 B.使用CloseDoc关闭当前已有文档[文档510903556]。
     */
    this.thinkEditor.CloseDoc(this.thinkEditor.docName)
    this.OpenEmrCommonHandle(doc_name, data, doc_type, enableRevise);

    // if (this.thinkEditor._IsNull(view_mode)) {
    //   view_mode = E_VIEW_MODE.Edit;
    // }

    thinkEditor.SetViewMode(view_mode);

    var end1 = new Date().getTime();

    /*  //@20220226 测试痕迹
     const json = {};
     json.display_revise_auxiliary = true;
     json.display_revise_del = false;
     json.display_qualitycontrol_infobox = false;
     json.display_comment_infobox = false;
     json.display_edit_auxiliary = true;
     json.display_selection_effect = true;
     json.display_carriage_return = false;
     this.thinkEditor.SetViewMode(view_mode, json);//E_VIEW_MODE.Edit*
     */
  }

  /**
   * 示例：通过http获取病历并打开
   *
   * @param {string} doc_name
   * @param {E_DOC_TYPE} doc_type
   * @param {string} doc_file
   * @param {E_VIEW_MODE} view_mode
   * @memberof ThinkEditorDemo
   */
  async OpenEmr(doc_name, doc_type, docData, viewMode, enableRevise) {
    if (typeof doc_type === 'undefined') {
      doc_type = E_DOC_TYPE.Entity;
    }

    await this.OpenEmrCommon(doc_name, docData, doc_type, viewMode, enableRevise);
    let thinkEditor = this.thinkEditor;
    thinkEditor.SetDefaultFont('宋体', '小五');
  }
}
